﻿using System;
using System.IO;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using System.Net;
using WechatModule.Model;

namespace WechatModule.Tool
{
    public class ReuqestTool
    {
        /// <summary>
        /// 请求一个API返回JS
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public static string GetWechatJson(string url)
        {
            string returnText;
            using (WebClient wc = new WebClient()) {
                wc.Credentials = CredentialCache.DefaultCredentials;
                wc.Encoding = Encoding.UTF8;
                returnText = wc.DownloadString(url);
                
                //if (returnText.Contains("errcode"))
                //{
                //    //可能发生错误
                //  每次回来的成员不固定所以作废
                //    var error = JsonHelper.ParseFromJson<Error>(returnText);
                //    throw new Exception("微信返回错误：Code:" + error.errcode + " 错误信息：" + error.errmsg);
                //}
            }
            return returnText;
        }
    }
}
